package com.xlj.service;

import com.xlj.dao.userMapper;
import com.xlj.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service("userService")
public class userServiceimp implements userService {
   @Autowired
private userMapper userMapper;

    public void setUserMapper(userMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public List<User> getAll() {
        return userMapper.getAll();
    }

    @Override
    public List<User> getAlls() {
        return userMapper.getAlls();
    }
    @Override
    public List<User> getAllrole() {
        return userMapper.getAllrole();
    }
    @Override
    @Transactional(readOnly = true)
    public List<User> getuaddress() {
        return userMapper.getuaddress();
    }
    @Override
    @Transactional(propagation = Propagation.REQUIRED )
    public Integer addnewUser(User user) {
        return userMapper.addnewUser(user);
    }

    @Override
   @Transactional
    public Integer addNewUsers(List<User> users) {
        for (User user:users){
            this.addnewUser(user);
           throw new RuntimeException("添加模拟异常");
        }
        return 1;
    }
}
